package vn.com.pavibook.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vn.com.pavibook.dao.AccountDao;
import vn.com.pavibook.dao.PublisherDao;
import vn.com.pavibook.domain.model.Account;
import vn.com.pavibook.domain.model.Publisher;
import vn.com.pavibook.model.vo.PublisherVO;

@Service
public class PersonalInfoService {
	
	@Autowired
	private PublisherDao publisherDao;
	@Autowired
	private AccountDao accountDao;
	
	public PublisherVO getPersonalInfo(String username){
		List<Publisher> publishers = publisherDao.getPersonalInfo(username).getSearchResult();
		if(publishers.size() == 0) return new PublisherVO(); 
		Publisher publisher = publishers.get(0);
		PublisherVO publisherVO = new PublisherVO(
				publisher.getId(), publisher.getName(), 
				publisher.getTitle(), publisher.getAddress(), publisher.getBossName(), 
				publisher.getPhone(), publisher.getEmailBussiness(), publisher.getAccountId(), 
				publisher.getRegisterDate(), publisher.getActive(),publisher.getDescription());
		
		return publisherVO; 
	}
	public PublisherVO getPersonalInfoById(int id){
		List<Publisher> publishers = publisherDao.getPersonalInfoById(id).getSearchResult();
		if(publishers.size() == 0) return new PublisherVO();
		Publisher publisher = publishers.get(0);
		PublisherVO publisherVO = new PublisherVO(
				publisher.getId(), publisher.getName(), 
				publisher.getTitle(), publisher.getAddress(), publisher.getBossName(), 
				publisher.getPhone(), publisher.getEmailBussiness(), publisher.getAccountId(), 
				publisher.getRegisterDate(), publisher.getActive(), publisher.getDescription());
		
		return publisherVO; 
	}
	
	public Account getAccountById(int id){
		return accountDao.getAccountById(id);
	}
	
	public void updateAccount(Account account){
		accountDao.updateAccount(account);
	}
}
